package com.lagou.common;

import com.lagou.vo.CityVo;
import com.lagou.vo.ProvinceVo;

import java.util.ArrayList;
import java.util.List;

public class CityProvinceConverter {


    /**
     * 将cityList中的招聘数 转换到 provinceVoList中
     * @param cityList
     * @param provinceVoList
     * @return
     */
    public static List<ProvinceVo> converter(List<CityVo> cityList, List<ProvinceVo> provinceVoList) {



        //循环省
        flag :for (ProvinceVo provinceVo : provinceVoList) {
            long sumCount = 0;
            //省的名称
            String provinceName = provinceVo.getName();

            List<CityVo> pCityList = provinceVo.getCity();

            List<String> pCityNameList = new ArrayList<>();


            for (CityVo cityVo : pCityList) {
                pCityNameList.add(cityVo.getCName());//填充城市名称
            }

            //循环cityList
            for (CityVo cityVo : cityList) {
                //判断省名称不要是 北京上海重庆天津

                if ("北京".equals(provinceName)&&"北京".equals(cityVo.getCName())) {
                    provinceVo.setValue(cityVo.getNum());
                    continue flag;
                }else if ("上海".equals(provinceName)&&"上海".equals(cityVo.getCName())) {
                    provinceVo.setValue(cityVo.getNum());
                    continue flag;
                }else if ("天津".equals(provinceName)&&"天津".equals(cityVo.getCName())) {
                    provinceVo.setValue(cityVo.getNum());
                    continue flag;
                }else if ("重庆".equals(provinceName)&&"重庆".equals(cityVo.getCName())) {
                    provinceVo.setValue(cityVo.getNum());
                    continue flag;
                }else{
                    if (pCityNameList.contains(cityVo.getCName())){
                        sumCount += cityVo.getNum();
                    }
                }
                provinceVo.setValue(sumCount);
            }

        }

        return provinceVoList;
    }
}
